package site.yunnong.atvris.portal.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;
import site.yunnong.atvris.common.api.ResultVO;
import site.yunnong.atvris.common.utils.IPUtils;
import site.yunnong.atvris.service.InteractionService;
import site.yunnong.atvris.common.dto.InteractionParam;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @author zjh
 * @date 2021/9/9 9:23
 */
@Api("点击相关功能")
@RequestMapping("/interaction")
@RestController
@Slf4j
public class InteractionController {

    @Resource
    private InteractionService interactionService;
    
//    @ApiOperation("视频进入用户视图，视频曝光量统计")
    @PostMapping("/exposure")
    public ResultVO exposure(@RequestBody InteractionParam param) {
        interactionService.exposure(param);
        return new ResultVO().success();
    }

    @ApiOperation("用户点击媒体，统计媒体点击量")
    @PostMapping("/click")
    public ResultVO click(@RequestBody InteractionParam param, HttpServletRequest request) {
        if (StringUtils.isEmpty(param.getIp())) {
            param.setIp(IPUtils.getIpAddr(request));
        }
        interactionService.click(param);
        return new ResultVO().success();
    }

    @ApiOperation("用户播放媒体，统计数据")
    @PostMapping("/view")
    public ResultVO view(@RequestBody InteractionParam param) {
        interactionService.view(param);
        return new ResultVO().success();
    }

    @ApiOperation("用户点赞/取消点赞媒体，统计数据")
    @PostMapping("/like")
    public ResultVO like(@RequestBody InteractionParam param) {
        interactionService.like(param);
        return new ResultVO().success();
    }
    
    @ApiOperation("添加或取消收藏")
    @PostMapping("/star")
    public ResultVO star(@RequestBody InteractionParam param) {
        interactionService.star(param);
        return new ResultVO().success();
    }
    
    @ApiOperation("关注某个用户")
    @PostMapping("/follow")
    public ResultVO follow(@RequestParam("uuid") Long uuid) {
        interactionService.follow(uuid);
        return new ResultVO().success();
    }

    @ApiOperation("取关某个用户")
    @PostMapping("/unfollow")
    public ResultVO unfollow(@RequestParam("uuid") Long uuid) {
        interactionService.unfollow(uuid);
        return new ResultVO().success();
    }
}

